<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.Date"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>OA协同办公系统</title>
<link href="css/background.css" rel="stylesheet" type="text/css" />
<link href="css/table.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/openwindow.js"></script>
<script src="js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript">
	function taskSave(){
		var url="taskSave.action";
		openWindow(url,804,604);
	}
	
	function taskNew(taskId){
		var url="taskNew.action?taskId="+taskId;
		openWindow(url,804,604);
	}
	
	function taskNewEnd(taskId){
		var url="taskNewEnd.action?taskId="+taskId;
		openWindow(url,804,604);
	}
	
	function taskUpdate(taskId){
		var url="taskUpdate.action?taskId="+taskId;
		openWindow(url,804,604);
	}
	
	function daleteTask(){
		var arry="";
		var count=0;
		var checks = $("input[name='ids']");
		for(var i=0;i<checks.length;i++){
			if(checks[i].checked){
				if(arry==''){
				arry+="ids="+checks[i].value;
			}else{
				arry+="&ids="+checks[i].value;
			}
				count++;
			}
		}
		if(count==0){
			alert("请选择要删除的数据！");
			return;
		}
	if(confirm("确定要删除？")){
		$.post("deleteTask.action",arry,function(data){
			if(data=="success"){
				alert("删除数据成功！");
				window.location.reload();
			}else{
				alert("删除数据失败！");
			}
		});
	}
	}
function searchByDay(time,val){
	if(val=='1'){
	window.location.href="taskListByDay.action?time="+time+"&status="+val;
	}else if(val=='2'){
	window.location.href="taskListByMonth.action?status="+val;
	}else{
		window.location.href="taskList.action?status="+val;
	}
}
$(function(){
	var status=$("#status").val();
	var arra=document.getElementsByName("queryTimeType");
	for(var i=0;i<arra.length;i++){
		if(status==arra[i].value){
			arra[i].checked=true;
			break;
		}
	}
});

function dateSearch(val){
	var time=$("#time").val();
	var date= new Date(Date.parse(time.replace(/-/g,   "/")));
	var date2;
	if(val=="+"){
		 date2=new Date(date.getFullYear(),date.getMonth(),date.getDate()+1);
	}else{
		 date2=new Date(date.getFullYear(),date.getMonth(),date.getDate()-1);
	}
	time=date2.getFullYear()+"-"+(date2.getMonth()+1)+"-"+date2.getDate();
	window.location.href="taskListByDay.action?time="+time+"&status=1";
}
$(function(){
      $("#tabllist #row:odd").addClass("reigh_list3"); //even odd 为jquery的方法，even为偶数，odd为奇数。特别注意：索引从0开始，所以第一行是偶数！
	  $("#tabllist #row:even").addClass("reigh_list4"); 
});

function overStyle(ths){
		ths.className='reigh_list5';
	}
	
function outStyle(ths){
		ths.className=ths.className.replace('reigh_list5','');
     	$("#tabllist #row:odd").addClass("reigh_list3"); //even odd 为jquery的方法，even为偶数，odd为奇数。特别注意：索引从0开始，所以第一行是偶数！
	    $("#tabllist #row:even").addClass("reigh_list4"); 
	}
	
function checkAll(){
	var all=$("#all");
	var checks=$("input[name='ids']");
	if(all.attr("checked")){
		checks.attr("checked","checked");
	}else{
		checks.attr("checked","");
	}
}

function checkodd(){
	var conm=0;
	var all=$("#all");
	var checks=$("input[name='ids']");
	for(i=0;i<checks.length;i++){
		if(checks[i].checked){
			conm++;
		}
	}
	if(conm==checks.length){
		all.attr("checked","checked");
	}else{
		all.attr("checked","");
	}
}
</script>
</head>
<body>
<input type="hidden" id="time" value="${time}">
<input type="hidden" id="status" value="${status }">
<table  border="0" cellpadding="0" cellspacing="0" width="100%">
  <tbody>
  <tr>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
    <td style="background: url('image/wsoa_window_002.gif');"><table border="0" cellpadding="0" cellspacing="0">
      <tbody><tr>
        <td align="center" style="background: url('image/wsoa_window_002.gif');" width="10"><img src="image/center_19.gif"></td>
        <td align="center" style="background: url('image/wsoa_window_002.gif');"></td>
        <td>个人办公 &gt; 日程安排 &gt; 日程建立</td>
        </tr>
    </tbody>
    </table></td>
    <td style="background: url('image/wsoa_window_002.gif');" width="1"></td>
  </tr>
  <tr>
    <td style="background: url('image/wsoa_window_010.gif');"  width="1">&nbsp;</td>
    <td>
    
		<table align="center" height="15" width="100%"><tbody><tr><td></td></tr></tbody></table>
	<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
		<tbody><tr>
			<td align="left" width="65%;"><span>	
			<input name="queryTimeType" value="0" checked="checked" onClick="searchByDay('','0')" class="noprint" type="radio">列表查看
			<input name="queryTimeType" value="1" onClick="searchByDay('','1')" class="noprint" type="radio">按天查看
			<input name="queryTimeType" value="2" onClick="searchByDay('','2')" class="noprint" type="radio">按月查看
			</span>
			</td>
			<td align="right" background="taskCx_files/wsoa_window_015.htm" width="40%">
			<span id="errorId"></span>
			<input class="button_02" name="b1" onClick="taskSave()" title="Add" value="增加" accesskey="a" type="button">		
			<input class="button_02" onClick="daleteTask()" value="删除" title="Delete" accesskey="d" type="button">			
			</td>
		</tr>
	</tbody></table>
<!-- 按周 -->
<table width="100%">
<tbody><tr>
<td style="vertical-align: top;" width="72%">
<table width="100%">
<tr>
<td align="center"><a href="javascript:dateSearch('-')"   class="linkStyle">&lt;&lt; </a><span id="dateTime"></span><script type="text/javascript">
	var time=$("#time").val();
	var date= new Date(Date.parse(time.replace(/-/g,   "/")));
	var year=date.getFullYear(); var months=date.getMonth()+1;var day=date.getDate();
	var week="";
	if(date.getDay()==0){
  	  week="星期日";
   }else if(date.getDay()==1){
  	  week="星期一";
   }else if(date.getDay()==2){
  	   week="星期二";
   }else if(date.getDay()==3){
  		week="星期三";
  }else if(date.getDay()==4){
  		week="星期四";
  }else if(date.getDay()==5){
  		week="星期五";
  }else if(date.getDay()==6){
  		week="星期六";
  }
	$("#dateTime").html(year+"年"+months+"月"+day+"日&nbsp;&nbsp;"+week);
</script><a href="javascript:dateSearch('+')"   class="linkStyle">&gt;&gt;  </a></td>
</tr>
</table>
<table style="margin-top: 10px" id="tabllist" class="righ_list" frame="box" cellspacing="1" cellpadding="0" width="100%"  border="0">
<tbody>
<tr class="reigh_list2">
	<th width="5%"><input onclick="checkAll()"  type="checkbox" id="all" /></th>
	<th width="15%">开始时间</th>
	<th width="15%">结束时间</th>
	<th>主题</th>
	<th width="10%">完成状态</th>
	<th width="7%">操作</th>
</tr>
<c:if test="${empty taskList}">
<tr id="row">
	<td colspan="7">
		没有相关数据！
	</td>
</tr>
</c:if>
<c:set var="date"><fmt:formatDate value="${date}" pattern="yyyy-MM-dd" /></c:set>
<c:forEach items="${taskList}" var="task">
<c:set var="startDate"><fmt:formatDate value="${task.startTime}" pattern="yyyy-MM-dd" /></c:set>
<c:set var="endDate"><fmt:formatDate value="${task.endTime}" pattern="yyyy-MM-dd" /></c:set>
<tr id="row" onmouseover="overStyle(this)" onmouseout="outStyle(this)">
	<td align="center">
	<input type="checkbox" name="ids" value="${task.id }" onclick="checkodd()" />
	</td>
	<td>
	<fmt:formatDate value="${task.startTime}" type="date" pattern="yyyy-MM-dd"/>
	</td>
	<td>
	<fmt:formatDate value="${task.endTime}" type="date" pattern="yyyy-MM-dd"/>
	</td>
	<td>
			<c:choose>
				<c:when test="${date>endDate}">
					<a href="javascript:taskNewEnd('${task.id }')"> <font
						style="text-decoration: line-through">${fn:substring(task.title,0,25 )
							}</font> </a>
				</c:when>
				<c:otherwise>
					<a href="javascript:taskNew('${task.id }')">
						${fn:substring(task.title,0,25 )} </a>
				</c:otherwise>
			</c:choose>
		</td>
		<td>
			<c:if test="${date<startDate}">
			未开始
			</c:if>
			<c:if test="${startDate<=date&&date<=endDate}">
			办理中
			</c:if>
			<c:if test="${date>endDate}">
			已结束
			</c:if>
		</td>
	<td align="center">
		<img alt="修改" onclick="taskUpdate('${task.id }')" src="image/operate_update.gif" style="cursor: pointer">
	</td>
</tr>
</c:forEach>
</tbody>

</table>
<!-- 按月 -->
</td>
<td style="vertical-align: top;" align="right" width="220px">
<br><br>
	<div id="div1" style="width: 200px"></div>
		<script>
			var time=$("#time").val();
			WdatePicker({eCont:'div1',onpicked:function(dp){
			 	window.location.href="taskListByDay.action?time="+dp.cal.getDateStr()+"&status=1";
			}})
			</script>
</td>
</tr>
</tbody>
</table>

     </td>
<td style="background: url('image/wsoa_window_006.gif');"  width="1">&nbsp;</td></tr>
  <tr>
    <td height="1" width="1"><img src="image/wsoa_window_009.gif" height="16" width="14"></td>
    <td style="background: url('image/wsoa_window_008.gif');" height="1"></td>
    <td height="1" width="1"><img src="image/wsoa_window_007.gif" height="16" width="12"></td>
  </tr>
</tbody>
</table>
</body>
</html>